package com.yyr.bluetoothpair;

import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Looper;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/22.
 */

public class BluetoothPairService {

    HashMap<String,BluetoothStateListener> mBluetoothStateListeners = new HashMap<String,BluetoothStateListener>();
    static BluetoothAdapter mBluetoothAdapter;
    interface  BluetoothListener{
        //Device does not support Bluetooth
            void  noSupport();
    }
    private BluetoothPairService() {
        mBluetoothStateListeners = new HashMap<String,BluetoothStateListener>();
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    }

    static class BluetoothPairServiceHelpe {
        static final BluetoothPairService bluetoothPairService = new BluetoothPairService();
    }

    public BluetoothPairService getInstance() {

        return BluetoothPairServiceHelpe.bluetoothPairService;
    }

    public static BluetoothAdapter getBluetoothAdapter() {
        if (mBluetoothAdapter == null) {
            mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        }
        return mBluetoothAdapter;
    }
    private  static int getBluetoothState() {
        BluetoothAdapter adapter = getBluetoothAdapter();
        return adapter != null ? adapter.getState() : 0;
    }
    public static boolean isBluetoothEnabled() {
        return getBluetoothState() == BluetoothAdapter.STATE_ON;
    }


    public static boolean openBluetooth() {
        BluetoothAdapter adapter = getBluetoothAdapter();
        if (adapter != null) {
            return adapter.enable();
        }
        return false;
    }
    public void registerBluetoothStateListener(String  macAddress,BluetoothStateListener listener) {
        mBluetoothStateListeners.put(macAddress,listener);
    }
    interface  BluetoothStateListener{
         void onBluetoothStateChanged(String  macAddress,boolean openOrClosed);
    }
    public void unregisterBluetoothStateListener(String  macAddress){

    }
}
